package com.nervenets.web.controller.handler.user.wealth;

import com.nervenets.web.controller.handler.Handler;
import com.nervenets.web.controller.handler.common.UserPagingParams;
import com.nervenets.web.enumeration.OperateType;
import com.nervenets.web.enumeration.WealthType;
import com.nervenets.web.hibernate.domain.user.WealthFlow;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

public class UserRewardWithdrawsHandler extends Handler<UserPagingParams> {
    @Override
    public String handle(UserPagingParams params, HttpServletRequest request) throws Exception {
        String hql = "from WealthFlow where userId = :userId and wealthType = :wealthType and operateType between :startType and :endType order by id desc ";
        HashMap<String, Object> objects = new HashMap<>();
        objects.put("userId", params.getUserId());
        objects.put("wealthType", WealthType.reward);
        objects.put("startType", OperateType.rewardWithdrawFee);
        objects.put("endType", OperateType.rewardWithdraw);
        List<WealthFlow> flows = userDao.getAllObjectsByHql(hql, objects, params.getStart(), params.getLimit());
        return successMessage(flows);
    }

    @Override
    public String result() throws Exception {
        return successMessage();
    }
}
